﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Silverlight.ControlToolkit.Validator;
using Silverlight.ControlToolkit.Windows;
using Silverlight.ControlToolkit.ControlService;

namespace Test.Silverlight.ControlToolkit
{
    public partial class ValidatorDemo : UserControl    
    {
        public ValidatorDemo()
        {
            InitializeComponent();

            //Validator.Validating += new ValidatingEventHandler(Validator_Validating);
            Validator.Validating += new ValidatingEventHandler(Validator_Validating);
        }

        void Validator_Validating(object sender, ValidatingEventArgs e)
        {
            if (e.TargetControl == txtCustom && !txtCustom.Text.Equals("ocdotnet"))
            {
                e.IsValid = false;
                e.ErrorMessage = "INVALID ENTRY";
            }
        }

        private void btnValidateAll_Click(object sender, RoutedEventArgs e)
        {
            //MessageWindow.Show("I'm Dirty ");

            if (BusyBox.AllOpenInstances.Count > 0)
                BusyBox.AllOpenInstances[0].CloseDialog();

            BusyBox.Show("Searching Customers", this.txtAmount);
            return;

            if (DirtyReadTracker.GetIsDirty(this.GridPanel))
            {
                MessageWindow.Show("I'm Dirty ");
                DirtyReadTracker.SetIsDirty(this.GridPanel, false);

            }
            else
                MessageWindow.Show("I'm clean ");

            return;

            if (Validator.ValidateContainer(this.GridPanel))
            {
                MessageWindow.Show("Validation successful ");
            }

        }



        //void Validator_Validating(object sender, ValidatingEventArgs e)
        //{
        //    if (e.TargetControl == txtRequired && !txtRequired.Text.Equals("LAC#"))
        //    {
        //        e.IsValid = false;
        //        e.ErrorMessage = "INVALID ENTRY";
        //    }
        //}

        //private void btnValidateAll_Click(object sender, RoutedEventArgs e)
        //{
        //    if (Validator.ValidateContainer(this.GridPanel))
        //    {
        //        MessageWindow.Show("Validation successful");
        //    }

        //    //if (DirtyReadTracker.GetIsDirty(this.GridPanel))
        //    //{
        //    //    MessageWindow.Show("I'm Dirty ");
        //    //    DirtyReadTracker.SetIsDirty(this.GridPanel, false);

        //    //}
        //    //else
        //    //    MessageWindow.Show("I'm clean ");

        //}

         

    }
}
